<template>
  <div>
    <div class="wy-filter">
      <el-input placeholder="请输入要搜索的疾病名称" v-model="query.diseaseName"></el-input>
      <el-input placeholder="请输入要搜索的疾病助记码" v-model="query.diseaseCode"></el-input>
      <el-input placeholder="请输入要搜索的疾病ICD" v-model="query.diseaseICD"></el-input>
      <el-button type="primary" @click="search">搜索</el-button>
      <el-button type="primary" @click="add">添加</el-button>
    </div>
    <el-table ref="wytable" :data="tableData">
      <el-table-column type="selection" width="55" />
      <el-table-column label="疾病编码" prop="diseaseCode"></el-table-column>
      <el-table-column label="疾病名称" prop="diseaseName"></el-table-column>
      <el-table-column label="国际ICD编码" prop="diseaseICD"></el-table-column>
      <el-table-column label="疾病类型" prop="diseaseCategory"></el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { get } from '@/util/axios'
import { ElMessage } from 'element-plus'
const emits = defineEmits(['update:tableData'],['update:show'])
const wytable = ref()
const query = reactive({
  diseaseCode: '',
  diseaseName: '',
  diseaseICD: ''
})
const tableData = ref([])
function search () {
  if (query.diseaseCode.trim() || query.diseaseName.trim() || query.diseaseICD.trim()) {
    getTableData()
  } else {
    ElMessage.error('至少要输入一个条件')
  }
}
function getTableData () {
  get('/disease/list', query, content => {
    tableData.value = content
  })
}
function add () {
  emits('update:tableData', wytable.value.getSelectionRows())
  emits('update:show', false)
}
</script>

<style scoped lang="scss">
</style>
